package icexam;


import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

class SplashWindow extends JWindow implements ActionListener {

    ICExamApp main;
    JLabel back = new JLabel(new ImageIcon("icexp.jpg"));//显示图形的标签
    JProgressBar progressBar = new JProgressBar(1, 100);//进度条
    Timer timer;
    int n = 100;

    public SplashWindow(ICExamApp main) {
        this.main = main;
        setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));//设置鼠标形状
        progressBar.setStringPainted(true);//允许进度条显示文本
        progressBar.setString("正在加载程序-----");//设置进度条文本
        getContentPane().add(back, "Center");
        getContentPane().add(progressBar, "South");
        setSize(542, 698);
        toFront();
//        setLocation(200, 200);
        Dimension   screensize=Toolkit.getDefaultToolkit().getScreenSize(); 
        Dimension   dialogSize   =   this.getSize(); 
        this.setLocation(screensize.width/2-542/2,screensize.height/2-698/2);
//        setLocation(screensize.width/2-dialog.width/2,screensize.height/2-dialog.height/2);
        setVisible(true);
        timer = new javax.swing.Timer(100, this);
        timer.addActionListener(this);
        timer.start();
    }

    public void actionPerformed(ActionEvent e) {
        if (--n > 0) {
            progressBar.setValue(100 - n);
            timer.restart();
        } else {
            timer.stop();
            dispose();
            JFrame jf = new javax.swing.JFrame();

            NewJDialog dialog = new NewJDialog(jf, true);
            dialog.setLocation(400,300);
            Point   p   =   jf.getLocation();
            Dimension   d   =   jf.getSize();
            int   x   =   p.x+(d.width-p.x)/2;     //计算
            int   y   =   p.y+(d.height-p.y)/2;
            dialog.setVisible(true);
            
            
            if(dialog.getReturnStatus()==1)
                main.show(new ICExamView(main));
            else{
                System.exit(-1);
            }
        }
    }

    public static void main(String[] args) {
//        new SplashWindow();
    }
}
